//
//  ComplaintViewController.m
//  jingdongfang
//
//  Created by MTiMac02 on 2017/8/31.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "ComplaintViewController.h"
#import "FeedBackViewController.h"

@interface ComplaintViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table;
@end

@implementation ComplaintViewController
#pragma mark -生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.title = @"投诉";
    self.title = NSLocalizedString(@"Complain", nil);
    self.view.backgroundColor =  [UIColor c2Color];
    self.table.delegate=self;
    self.table.dataSource=self;
    
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, 320)];
    view.backgroundColor=self.table.backgroundColor;
    UIButton *callBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    callBtn.frame = self.view.frame;
    [callBtn addTarget:self action:@selector(callPhone) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:callBtn];
    
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"complaint-tel"]];
    image.frame = CGRectMake(0, 75, 100, 100);
    image.contentMode = UIViewContentModeScaleAspectFit;
    [callBtn addSubview:image];
    image.centerX = view.centerX;
    
    UILabel *msg = [[UILabel alloc] initWithFrame:CGRectZero];
//    msg.text = @"您可以拨打人工客服电话";
    msg.text=NSLocalizedString(@"please call customer service", nil);
    msg.textColor=[UIColor c4Color];
    [msg setLineBreakMode:NSLineBreakByClipping];
    [msg setNumberOfLines:0];
    [msg setTextAlignment:NSTextAlignmentCenter];
    msg.font = [UIFont font18];
    [callBtn addSubview:msg];
    [msg sizeToFit];
    msg.center = image.center;
    msg.top = image.bottom+35;
    [view addSubview: msg];
    
    UILabel *tel = [[UILabel alloc] initWithFrame:CGRectZero];
    tel.font = [UIFont boldSystemFontOfSize:30];
    tel.textColor = [UIColor c1Color];
    tel.text = @"400-668-1000";
    [callBtn addSubview:tel];
    [tel sizeToFit];
    tel.center = msg.center;
    tel.top = msg.bottom+15;
    [view addSubview:tel];
    self.table.tableHeaderView=view;
    
}

#pragma mark -Delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    cell.textLabel.text=@"去留言";
    cell.textLabel.text = NSLocalizedString(@"Leave a Message", nil);
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            FeedBackViewController *feedBackVC = [[UIStoryboard storyboardWithName:@"Setting" bundle:nil] instantiateViewControllerWithIdentifier:@"FeedBackViewController"];
            [self.navigationController pushViewController:feedBackVC animated:YES];
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
- (void)callPhone
{
    [self presentViewController:[self callPhoneOfNumber: @[@"400-668-1000"]] animated:YES completion:nil];
}
-(UIAlertController *)callPhoneOfNumber:(NSArray *)mobileNumArr
{
    UIAlertController *aVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (int i = 0; i < mobileNumArr.count; i++) {
        UIAlertAction *callA = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@",mobileNumArr[i]] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",[NSString stringWithFormat:@"%@",mobileNumArr[i]]]];
            [[UIApplication sharedApplication] openURL:url];
        }];
        [aVC addAction:callA];
    }
    UIAlertAction *callB = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [aVC addAction:callB];
    return aVC;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

